#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long LL;
const int N = 1e4 + 10;
priority_queue<int, vector<int>, greater<int>>heap;
int n;
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        heap.push(x);
    }
    LL ans = 0;
    for (int i = 0; i < n - 1; i++) {
        int ans1 = 0, ans2 = 0, ans3 = 0;
        if (heap.size()) {
            ans1 = heap.top();
            heap.pop();
        }
        if (heap.size()) {
            ans2 = heap.top();
            heap.pop();
        }
        ans3 = ans1 + ans2;
        ans += ans3;
        heap.push(ans3);
    }
    cout << ans << endl;
    return 0;
}